package ms07.ticket.activities;

import ms07.ticket.R;
import ms07.ticket.Ticket;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class ActivityTicketDetails extends Activity{
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);  
		this.setContentView(R.layout.ticket_details);
		
		Bundle extras = getIntent().getExtras();
		if(extras!=null){
			//woho -> this must be a valid ticket!!!
			
			//Ticket ticket = Ticket.getTicketInstance(extras.getLong("internal_id"));
			
			Ticket ticket = (Ticket)extras.getSerializable("ticket");
			
			this.showTicket(ticket);
		}
	}
	
	public void showTicket(Ticket ticket){
		TextView ticketTitle = (TextView)this.findViewById(R.id.ticketDetailsTitle);
		TextView ticketFrom = (TextView)this.findViewById(R.id.ticketDetailsFrom);
		TextView ticketTo = (TextView)this.findViewById(R.id.ticketDetailsTo);
		TextView ticketUser = (TextView)this.findViewById(R.id.ticketDetailsUser);
		TextView ticketPeople = (TextView)this.findViewById(R.id.ticketDetailsPeople);
		TextView ticketDate = (TextView)this.findViewById(R.id.ticketDetailsDate);
		TextView ticketValidation = (TextView)this.findViewById(R.id.ticketDetailsValidation);
		TextView ticketMemberCard = (TextView)this.findViewById(R.id.ticketDetailsMemberCard);
		TextView ticketPrice = (TextView)this.findViewById(R.id.ticketDetailsPrice);
		
		ticketTitle.setText(ticket.getOrganisation());
		ticketFrom.setText(ticket.getCity_from());
		ticketTo.setText(ticket.getCity_to());
		ticketUser.setText(ticket.getUsername());
		ticketDate.setText(ticket.getValid_till().toLocaleString());
		String people = "";
		if(ticket.getAdults()>0){
			people+= String.valueOf(ticket.getAdults());
			if(ticket.getAdults()>1){
				people+= " Erwachsene";
			}else{
				people+= " Erwachsener";
			}
		}
		if(ticket.getChildren()>0){
			if(!people.equals("")) people+=", ";
			people+= String.valueOf(ticket.getChildren());
			if(ticket.getChildren()>1){
				people+= " Kinder";
			}else{
				people+= " Kind";
			}
		}
		ticketPeople.setText(people);
		String validation = "";
		int i=1;
		for(String tmp: ticket.getValidation()){
			if(!validation.equals("")) validation+="\n";
			validation+="C"+(i++)+": "+tmp;
		}
		ticketValidation.setText(validation);
		ticketMemberCard.setText(ticket.getMemberCard()==null?"KEINE":ticket.getMemberCard());
		ticketPrice.setText(String.valueOf(ticket.getPrice())+" EUR");
	}
	
}
